package com.evaluation.config;

import lombok.Data;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 企业微信配置类
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "wechat.cp")
public class WeChatCpConfig {

    /**
     * 企业ID
     */
    private String corpId;

    /**
     * 应用ID
     */
    private Integer agentId;

    /**
     * 应用密钥
     */
    private String secret;

    /**
     * 授权回调地址
     */
    private String redirectUri;

    /**
     * 企业微信服务Bean
     */
    @Bean
    public WxCpService wxCpService() {
        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId(this.corpId);
        config.setAgentId(this.agentId);
        config.setCorpSecret(this.secret);

        WxCpService wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);

        return wxCpService;
    }
}

